package com.hctforgreen.greenservice;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import com.hctforgreen.greenservice.ui.adapter.FeedBackListAdapter;
import com.hctforgreen.greenservice.ui.handler.FeedBackListHandler;
import com.hctforgreen.greenservice.utils.LoginResultStoreUtil;
import com.hctforgreen.greenservice.utils.ThemeStoreUtil;
import com.umeng.analytics.MobclickAgent;

/**
 * 信息反馈板块中的
 * 我的反馈
 * 
 * @author Dhb
 * 
 */
public class MyFeedbackActivity extends ParentActivity {
	private boolean has_contact = false;
	private static final int REQUEST_CODE = 10000;
	private String dialPhone;// 拨打电话号码

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_my_feedback);

		initSkinLayout();

		initTitleButtonBar();
		initWindow();
	}

	private void initTitleButtonBar() {
		final TextView titleTv = (TextView) findViewById(R.id.tv_title);
		titleTv.setText(getString(R.string.feed_back_title_hint));

		final ImageButton backBtn = (ImageButton) findViewById(R.id.btn_back);
		backBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (getIntent().getBooleanExtra("fromMain", false)) {
					startActivity(new Intent(MyFeedbackActivity.this,
							MainActivityV2.class));
					finish();
				} else {
					finish();
				}

			}
		});
	}

	public void initWindow() {
		getFeedBackJsonByPersonId(LoginResultStoreUtil.get(this).personId);
	}

	private FeedBackListHandler handler;

	private void getFeedBackJsonByPersonId(String personId) {
		View convertView = findViewById(R.id.lyt_parent);
		ListView listView = (ListView) convertView
				.findViewById(R.id.lst_default_list);
		handler = new FeedBackListHandler(this, convertView, personId,
				dialPhone, false);
		new FeedBackListAdapter(listView, this, convertView,
				R.layout.layout_loading, R.layout.layout_reloading, handler);
	}

	@Override
	protected void onResume() {
		super.onResume();
		if (has_contact) {
			has_contact = !has_contact;
			Intent intent = new Intent();
			intent.setClass(MyFeedbackActivity.this,
					SubmitPhoneFeedBackActivity.class);
			startActivity(intent);
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode != RESULT_OK)
			return;
		if (requestCode == REQUEST_CODE) {
			handler.refersh();
		}
	}

	@Override
	protected void onDestroy() {

		super.onDestroy();
	}

	@Override
	public void onBackPressed() {
		if (getIntent().getBooleanExtra("fromMain", false)) {
			startActivity(new Intent(MyFeedbackActivity.this,
					MainActivityV2.class));
			finish();
		} else {
			finish();
		}
		super.onBackPressed();
	}
}
